﻿using Newtonsoft.Json;
using System.Linq;
using System.Text;
using System.Web.Http;
using Yyyg.Models;

namespace Yyyg.WebUI.Api.Controllers
{
    public class GoodController : ApiController
    {
        [HttpGet]
        public string Get(string jdis)
        {
            //jdis:客户端的购物车rhid集合
            string[] ids = JsonConvert.DeserializeObject<string[]>(jdis);
            if (ids == null || ids.Length == 0) return "[]";
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < ids.Length; i++)
            {
                if (ids[i] != null)
                    builder.Append(i == ids.Length - 1 ? ids[i] : ids[i] + ",");
            }
            string sql = "select * from Rushby_all where Id in (" + builder + ")";
            using (LuckyEntities db = new LuckyEntities())
            {
                //匹配到所有指定夺宝项详细信息
                var que = db.Rushby_all.SqlQuery(sql);
                var res = que.Select(s => new
                {
                    rushID = s.Id,
                    title = s.Goods.Title,
                    src = s.Goods.GetMainImgPath(),
                    rem = s.Rem
                });
                //回送到客户端,将其展示到购物车栏
                return JsonConvert.SerializeObject(res);
            }
        }
    }
}